package com.yanqu.road.server.cmd.activity.rankunionwar.cross;

import com.yanqu.road.entity.activity.rankunionwar.config.RankUnionWarConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RankUnionWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.rankunionwar.RankUnionWarMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Cmd(code = GameProtocol.S_RANKUNIONWAR_CROSS_GET_PATRONS, desc = "")
public class RankUnionWarCrossGetPatronsCmd extends AbstractCommand {

    int activityId;
    int turn;
    Map<Long,List<Integer>> userIdMap = new ConcurrentHashMap<>();
    Map<Long,String> userUnionIdMap = new ConcurrentHashMap<>();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RankUnionWarProto.CrossRankUnionWarGetPatronsReqMsg reqMsg = RankUnionWarProto.CrossRankUnionWarGetPatronsReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        turn = reqMsg.getTurn();
        for(RankUnionWarProto.CrossRankUnionWarGetPatronsInfoMsg infoMsg : reqMsg.getInfosList()){
            userIdMap.put(infoMsg.getUserId(),infoMsg.getPatronsIdList());
            userUnionIdMap.put(infoMsg.getUserId(),infoMsg.getUnionId());
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        RankUnionWarConfig config = RankUnionWarMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

        RankUnionWarMgr.syncUserPatronsData(activityId,turn,userIdMap,userUnionIdMap);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }
    }
}
